package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.dto.AdminUserWorkRoomExportDTO;
import com.sc.nft.entity.UserWorkRoom;
import com.sc.nft.entity.dto.UserWorkRoomPageDTO;
import com.sc.nft.entity.vo.UserWorkRoomExcludeWhiteListRankVO;
import com.sc.nft.entity.vo.UserWorkRoomPageVO;
import com.sc.nft.entity.vo.WorkRoomExportVO;
import com.sc.nft.mapper.UserWorkRoomMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;
import org.web3j.abi.datatypes.Int;

import java.util.Date;
import java.util.List;

/**
 * (UserWorkRoom)表Dao层
 *
 * @author wwc
 * @since 2023-07-18 17:25:08
 */
@Slf4j
@Repository
public class UserWorkRoomDao extends ServiceImpl<UserWorkRoomMapper, UserWorkRoom> {

    private UserCityServerCentreDao userCityServerCentreDao;

    public UserWorkRoom selectByUserId(Long userId) {
        LambdaQueryWrapper<UserWorkRoom> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(UserWorkRoom::getUserId, userId);
        return baseMapper.selectOne(lambdaQueryWrapper);
    }

    public List<UserWorkRoom> selectByUserIdList(List<Long> userIdList) {
        LambdaQueryWrapper<UserWorkRoom> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.in(UserWorkRoom::getUserId, userIdList);
        return baseMapper.selectList(lambdaQueryWrapper);
    }

    public Page<UserWorkRoomPageVO> selectPageList(UserWorkRoomPageDTO userWorkRoomPageDTO) {
        return baseMapper.selectPageList(userWorkRoomPageDTO.toMp(), userWorkRoomPageDTO);
    }



    /**
     * 获取指定集合中包含多少个社区网点
     *
     * @param userId
     * @return
     */
    public Integer getsHowManyCommunityOutletsAreIncludedInTheSpecifiedCollection(Long userId) {
        return baseMapper.getsHowManyCommunityOutletsAreIncludedInTheSpecifiedCollection(userId);
    }

    public Long accessTheNearestCityServiceCenter(Long id) {
        return baseMapper.accessTheNearestCityServiceCenter(id);
    }


    public List<WorkRoomExportVO> workRoomExport() {
        return baseMapper.workRoomExport();
    }

    public List<UserWorkRoom> getList() {
        return new UserWorkRoom().selectAll();
    }

    public AdminUserWorkRoomExportDTO getDataByUserId(Long userId) {
        // 备注：涉及 sc_second_order 表查询，内置条件查询30天内数据，不必修改
        return baseMapper.getDataByUserId(userId);
    }

    public void insertUserWorkRoomDataTemp(AdminUserWorkRoomExportDTO workRoomExportDTO) {
        baseMapper.insertUserWorkRoomDataTemp(workRoomExportDTO.getUserId(),workRoomExportDTO.getName(),workRoomExportDTO.getUserTel(),workRoomExportDTO.getUnderResident(),workRoomExportDTO.getNftCost(),workRoomExportDTO.getNftIssuePrice(),workRoomExportDTO.getUnderMeltCost(),workRoomExportDTO.getValidUser(),workRoomExportDTO.getUserTradeNum(),workRoomExportDTO.getFirstIssueNum(),workRoomExportDTO.getSecondIssueNum());
    }

    public List<AdminUserWorkRoomExportDTO> getDataList() {
        return baseMapper.getDataList();
    }


    /**
     * 获取排除社区工作室和城市服务中心的用户
     * @param userId 用户id
     * @param exclude 是否排除社区网点
     * @return
     */
    public List<Long>getUsersWhoExcludeUsersFromCommunityStudiosAndCityServiceCenters(Long userId,Boolean exclude) {
        return baseMapper.getUsersWhoExcludeUsersFromCommunityStudiosAndCityServiceCenters(userId,exclude);
    }


    /**
     * 获取排除白名单的用户
     * @return
     */
    public List<UserWorkRoomExcludeWhiteListRankVO> getUserWorkRoomExcludeWhiteListRank() {
        return baseMapper.getUserWorkRoomExcludeWhiteListRank();
    }

    public Integer getCount(){
        LambdaQueryWrapper<UserWorkRoom> lambdaQueryWrapper = Wrappers.lambdaQuery();
        return baseMapper.selectCount(lambdaQueryWrapper);
    }
    public UserWorkRoom getByUserId(Long userId) {
        LambdaQueryWrapper<UserWorkRoom> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(UserWorkRoom::getUserId, userId);
        return baseMapper.selectOne(lambdaQueryWrapper);
    }

    public Integer getUserWorkRoomExcludeExchequerList(Long userId, Date startTime, Date endTime) {
        return baseMapper.getUserWorkRoomExcludeExchequerList(userId,startTime,endTime);
    }
}
